//
//  LabelSelectCell.m
//  OrderSys
//
//  Created by JM on 15/10/11.
//  Copyright © 2015年 zjlskj. All rights reserved.
//

#import "LabelSelectCell.h"
#import "JMPickerView.h"
@interface LabelSelectCell()<JMPickerViewDelegate>
@property(nonatomic, retain)NSMutableString *forOutStirng;
@end

@implementation LabelSelectCell
- (NSString *)forOutStirng {
    if (!_forOutStirng) {
        _forOutStirng = [NSMutableString string];
    }
    return _forOutStirng;
}
- (void)awakeFromNib {
    // Initialization code
}
+ (NSString *)ID
{
    return @"JMEdietrCell";
}

+ (instancetype)editerCell
{
    NSArray* nibs = [[NSBundle mainBundle] loadNibNamed:@"JMEdietrCell" owner:nil options:nil];
    return [nibs firstObject];
}

- (NSInteger)height {
    return self.frame.size.height;
}

//- (BOOL)textFieldShouldReturn:(UITextField *)textField {
//    [self.rightEditer resignFirstResponder];
//    return YES;
//}

+ (instancetype)cell {

        LabelSelectCell *cell =  [[LabelSelectCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[LabelSelectCell ID]];
        cell.leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 40)];
        cell.leftLabel.backgroundColor = [UIColor clearColor];
        cell.leftLabel.font = [UIFont systemFontOfSize:16];
        cell.leftLabel.tag = 1;
        [cell.contentView addSubview:cell.leftLabel];
        
        cell.rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 5, 200, 30)];
        cell.rightLabel.backgroundColor = [UIColor clearColor];
        cell.rightLabel.font = [UIFont systemFontOfSize:16];
        cell.rightLabel.tag = 2;
        [cell.contentView addSubview:cell.rightLabel];
        cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"圆箭头-50x50向下.png"]];
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark--
- (void)didSelect {
    [JMPickerView PopViewWithYYString:self.forOutStirng andIn:self.tableView andTitle:self.leftLabel.text andArray:self.forSelectArray with:self];
}

//JMPickerView delegate
-(void) didSeleted:(int) index {
    self.rightLabel.text = self.forSelectArray[index];
}
- (NSString *)valueData {
    return self.forOutStirng;
}
- (void)setValueData:(NSString *)valueData {
    NSAssert(valueData, @"非空错误");
    [self.forOutStirng setString:valueData];
}

+ (LabelSelectCell *)cellWithLabel:(NSString *)labelText forSelectArray: (NSArray*) aArray tableView:(UITableView *) tableView {
    LabelSelectCell * cell = [LabelSelectCell cell];
    cell.leftLabel.text = labelText;
    cell.forSelectArray = aArray;
    cell.tableView = tableView;
    return cell;
}
@end
